Skip to content

implement messageFormat transformer [WIP]#48

Draft
lunarW1TCH wants to merge 6 commits intonanostores:mainfrom
lunarW1TCH:message_format
Draft

implement messageFormat transformer [WIP]#48
lunarW1TCH wants to merge 6 commits intonanostores:mainfrom
lunarW1TCH:message_format

Conversation

@lunarW1TCH
Copy link
Copy Markdown
Contributor

Typescript-side implementation of messageFormat transformer based on MessageFormat 2 standard (see #39).

I wanted to get some feedback before trying to implement actual transform in javascript. For now I have fully typed the transformer and created tests for the types. Hence this PR is WIP.

This implementation supports only variables and markup from MF2 standard for now. Functions and matchers are unsupported.

import { messageFormat } from '@nanostores/i18n'
import { i18n } from '../stores/i18n'

export const messages = i18n('component', {
   click: messageFormat('Click {#link}here{/link}'),
   greeting: messageFormat('Welcome {$user}! {#star/}')
})
const t = useStore(messages)

t.click({ link: (content) => `<a href="https://github.com/nanostores/i18n">${content}</a>` }) // => 'Click <a href="https://github.com/nanostores/i18n">here</a>'
t.greeting({ user: 'Jane', star: () => '⭐' }) // => 'Welcome Jane! ⭐'

Is there anything I should change in types before I start implementing js code?

@lunarW1TCH lunarW1TCH changed the title implement messageFormat transformer implement messageFormat transformer [WIP] Apr 22, 2026
@ai
Copy link
Copy Markdown
Member

ai commented Apr 22, 2026

Very interesting PR! I am waiting more implementation to review (types looks like working according to the tests, the modern TS is an encrypted code not for humans anyway)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants